import axios from 'axios';
import { message } from 'antd';

const request = axios.create({
  baseURL: 'http://192.168.0.62:8080/api/game',
  timeout: 5000,
});

// 请求拦截器
// request.interceptors.request.use(
//     config => {
//         const token = store.state.token;
//         if (token) {
//             config.headers['Authorization'] = 'Bearer ' + token;
//         }
//         return config;
//     },
//     error => {}
// );

// 响应拦截器
request.interceptors.response.use(
  // console.log("");
  (resp) => {
    // console.log('响应拦截器数据响应', resp);
    var responseData = resp.data;
    const { code, data, msg, status } = responseData;
    code === 0 || status === 200 ? message.success(msg) : message.error(msg);
    return resp;
  },
  (err) => {
    message.error('未知错误');
  },
);

export default request;
